package com.ssm.service.impl;

import com.ssm.dao.CourseMapper;
import com.ssm.entity.Course;
import com.ssm.entity.CourseExample;
import com.ssm.service.CourseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("courseService")
public class CourseServiceImpl implements CourseService {
    @Resource(name = "courseMapper")
    private CourseMapper courseMapper;
    @Override
    public List<Course> listAllCourse() {
        return courseMapper.selectByExample(new CourseExample());
    }

    @Override
    public Integer createCourse(Course course) {
        return courseMapper.insert(course);
    }

    @Override
    public Integer update(Course course) {
        return courseMapper.insert(course);
    }

    @Override
    public Integer deleteCourse(int id) {
        return courseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Course getCourse(int id) {
        return courseMapper.selectByPrimaryKey(id);
    }

    @Override
    public String Coursename(int id) {
        CourseExample courseExample=new CourseExample();
        courseExample.or().andCourseidEqualTo(id);
        List<Course> list=new ArrayList<>();

        list= courseMapper.selectByExample(courseExample);
        Course course= list.get(0);
        return course.getCoursename();
    }
}
